package ihis.core;

import ihis.IIHISCore;
import ihis.core.fetcher.Fetcher;
import ihis.core.report.PerformanceReportFactory;
import ihis.core.report.PersonalScheduleReportFactory;
import ihis.core.report.ProjectScheduleReportFactory;
import ihis.core.report.ProjectScheduleRiskReportFactory;
import ihis.model.GeneralFilter;
import ihis.model.IHISConstants;
import ihis.model.Report;
import ihis.model.Task;
import ihis.model.TaskFilter;
import ihis.tms.client.IHISTMSClient;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class IHISCore implements IIHISCore{
	/* (non-Javadoc)
	 * @see ihis.IIHISCore#getReport(int, ihis.model.TaskFilter)
	 */
	@Override
	public Report getReport(int type, GeneralFilter filter) {
		switch(type){
		case IHISConstants.REPORT_PERSONAL_SCHEDULE:
			return new PersonalScheduleReportFactory().getReport(filter);
		case IHISConstants.REPORT_PROJECT_SCHEDULE:
			return new ProjectScheduleReportFactory().getReport(filter);
		case IHISConstants.REPORT_PERFORMANCE:
			return new PerformanceReportFactory().getReport(filter);
		case IHISConstants.REPORT_RISK:
			return new ProjectScheduleRiskReportFactory().getReport(filter);
		default:
			return null;
		}
	}

	/* (non-Javadoc)
	 * @see ihis.IIHISCore#getTaskList(ihis.model.TaskFilter)
	 */
	@Override
	public List<Task> getTaskList(TaskFilter filter) {
		IHISTMSClient client = new IHISTMSClient();
		client.setHostName("localhost");
		client.setServerPort(7403);
		return client.getTaskList(filter);
		
	}

	/* (non-Javadoc)
	 * @see ihis.IIHISCore#doFetch()
	 */
	@Override
	public void doFetch() {
		Date date = new Date(System.currentTimeMillis());			
		Calendar cal = Calendar.getInstance();
		cal.clear();
		cal.setTime(date);
		if(	cal.get(Calendar.HOUR_OF_DAY) == 0)
		{
			cal.set(Calendar.HOUR_OF_DAY, -1);
		}

		new Fetcher().doFetch("localhost", 7403, date);
	}
}